package com.zyl.demo.controller;

import com.zyl.demo.beans.BaseBean;
import com.zyl.demo.beans.Category;
import com.zyl.demo.beans.CategorySub;
import com.zyl.demo.beans.Commodity;
import com.zyl.demo.service.CategorySubService;
import com.zyl.demo.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    CategorySubService categorySubService;

    @Autowired
    CommodityService commodityService;
    @PostMapping("/getCategorySubList")
    public BaseBean getCategorySubList(int categoryId){
        List<CategorySub> categorySubList = categorySubService.getCategorySubByCategoryId(categoryId);
        return new BaseBean(categorySubList);
    }

    @PostMapping("/getCategorySubCommodityList")
    public BaseBean getCategorySubCommodityList(int categoryId,int categorySubId,int pageNum){
        if(pageNum-1<0){
            pageNum = 1;
        }
        List<Commodity> commodityList = commodityService.getCommodityByCategoryIdAndCategorySubId(categoryId,categorySubId,(pageNum-1)*10,10);
        return new BaseBean(commodityList);
    }
}
